<template>
	<view class="tab">
		<scroll-view class="tab-scroll" scroll-x>
			<view class="tab-scroll-box">
				<view v-for="(item,index) in list" :key="index" class="tab-scroll-item" :class="{active:activeIndex===index}" @click="clickTab(item,index)">{{item}}</view>
			</view>
		</scroll-view>
		<view class="tab-icon">
			<text class="iconfont icon-liebiao" size="50" color="#666" @tap="changeIcon" v-show="iconType"></text>
			<text class="iconfont icon-liebiao1" size="50" color="#666" @tap="changeIcon" v-show="!iconType"></text>
		</view>
	</view>
</template>

<script>
	export default {
		props:{
			//拿到外面传递来的list
			list:{
				type:Array,
				default (){
					return []
					
				}
			},
			sflag:{
				type:Boolean,
				default:true
			}
		},
		name:"tab",
		data() {
			return {
				activeIndex:0,
				iconType:'true'
			};
		},
		methods:{
			clickTab(item,index){
				//判断父组件是否点击了搜索，如果点击了，选项卡的高亮应该取消,不行应该点击搜索就取消这
				//实现选项卡的切换，返回茶叶类型
				//点击高亮
				console.log("是否搜索",this.sflag)
				
					this.activeIndex=index
					//传递事件,事件发射，子组件传给父组件
					this.$emit('tab',{
						//传递数据
						data:item,
						index:index,
						
					})
				
			},
			changeIcon(){
				this.iconType=!this.iconType
				this.$emit('cIcon',{
					//传递图表数据
					iconTy:this.iconType
				})
			}
		}
	}
</script>

<style lang="scss">
	// @import '../../common/css/icon.css';
	.tab{
		display: flex;
		height: 50px;
		width: 100;
		border-bottom: 1px #3F536E solid;
		background-color: #fff;
		box-sizing: border-box;
		position: sticky;
		
		.tab-scroll{
			//tab盛满整个元素
			flex: 1;
			overflow: hidden;
			box-sizing: border-box;
			// border: 1px red solid;
			.tab-scroll-box{
				display: flex;
				height: 45px;
				align-items: center;
				flex-wrap: nowrap;
				box-sizing: border-box;
				// background: #8EB981;
				.tab-scroll-item{
					flex-shrink: 0;
					padding: 5px 20px;
					color: #333333;
					font-size: 14px;
					//background: #C0C0C0;
					//border: 1px #808080 solid;
					//background: #8EB981;
					&.active{
						color: #ffaa00;
					}
				}
			}
		}
		
		.tab-icon{
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;
			width: 50px;
			&::after{
				content: '';
				position: absolute;
				top:12px;
				bottom: 12px;
				left: 0;
				width: 1px;
				background-color: #9c9696;
			}
		}
	}
</style>
